<?php require_once "./show.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link id="loadCss" type="text/css" href="./skin/default/layout.css" rel="stylesheet" />
<title>Nonsenser&#39;s Evil-I am just a Nonsenser</title>
<script src="./js/ajax.js" type="text/javascript" language="javascript"></script>
<script src="./js/post.js" type="text/javascript" language="javascript"></script>
<script src="./js/utility.js" type="text/javascript" language="javascript"></script>
</head>
<body topmargin="0">
<div id="container">
<?php

ShowHeader();
ShowSidebar();
ShowLogin();

$do = $_GET['do'];
if(!$do) $do = "ShowCategory";

echo "\n  <div id=\"ShowCategory\">\n";
$show_case = 0;
$curpage = 1;

switch(addslashes($do))
{
case "ShowCategory" :
	if(isset($_GET['cate_ID']) && is_numeric($_GET['cate_ID'])){
		$sqlCount = "select count(*) from blog_article where log_CateID =".$_GET['cate_ID'];
		$show_case = 0;
	}
	else if(isset($_GET['date']) && (strlen($_GET['date']) == 6)){ 
		$year = (int)substr(intval($_GET['date']),0,4);
		$month = (int)substr(intval($_GET['date']),4,2);
		//echo $year,$month;
		
		$start = strtotime($year."-".$month."-1");
		if($month == 12)
		{ $end = strtotime(($year+1)."-1-1"); }
		else{ $end   = strtotime($year."-".($month+1)."-1"); }
		
		$sqlCount = "select count(*) from blog_article where log_PostTime >= ".$start." and log_PostTime < ".$end;
		$show_case = 1;
	}
	else{
		$sqlCount = "select count(*) from blog_article ";
		$show_case = 2;
	}
	DoPage($sqlCount, $pagesize, $curpage, "./?do=ShowCategory&cate_ID=".$_GET['cate_ID']);
	
	switch($show_case)
	{
	case 0:
		$sqlData = "SELECT * FROM blog_article where log_CateID =".$_GET['cate_ID']." order by log_PostTime desc limit ".(($curpage-1)*$pagesize).",".$pagesize; 
		break;
	case 1:
		$sqlData = "SELECT * FROM blog_article where log_PostTime >= ".$start." and log_PostTime < ".$end." order by log_PostTime desc limit ".(($curpage-1)*$pagesize).",".$pagesize;
		break;
	case 2:
		$sqlData = "SELECT * FROM blog_article order by log_PostTime desc limit ".(($curpage-1)*$pagesize).",".$pagesize; 
		break;
	}
	//echo $sqlData;
	if($mysql->num_rows($sqlData) == 0) 
	{
		print <<<HTML
		<div align="center" style="clear:both; padding:20px;">No Article Posted Yet.</div>\n
HTML;
		break;
	}
	
	$rss = $mysql->select($sqlData);
	foreach( $rss as $rs )
	{
	   $time = strftime("%B %d,%Y,%H:%M %p", $rs[log_PostTime]);
print <<<HTML
		<div id=$rs[log_ID] class="article">
			  <div class="articletitle">
			  <a href="./?do=ShowSpecify&log_ID=$rs->log_ID">$rs[log_Title]</a>
			  </div>
			  <div class="articleshort">
			  $rs[log_Intro]<br><br><a href="./?do=ShowSpecify&log_ID=$rs[log_ID]">阅读全文</a>
			  </div>
			  <div class="articlefoot">
			  Author: $rs[log_Author] | Posted @ $time | <a href="./?do=ShowSpecify&log_ID=$rs->log_ID#PostComment">Comment($rs[log_CommNums])</a>
			  </div>
		</div>\n
HTML;
	}
	DoPage($sqlCount, $pagesize, $curpage, "./?do=ShowCategory&cate_ID=".$_GET['cate_ID']);
	break;
  
case "ShowSpecify" :
	if(!$_GET['log_ID'] or (!is_numeric($_GET['log_ID'])))
	{
		echo("No log_ID Specified");
		break;
	}
	$log_ID = $_GET['log_ID'];
	$sqlLog = "SELECT * FROM blog_article where log_ID = '".$_GET['log_ID']."'";
	$rs = $mysql->fetch_one_array($sqlLog);
	$commentable = $rs[log_IsCommentable];
	$time = strftime("%B %d,%Y,%H:%M %p",$rs[log_PostTime]);
print <<<HTML
	<div id="$rs->log_ID" class="article">
		<div class="articletitle">$rs[log_Title]</div>
		<div class="articlecontent">
		$rs[log_Content]
		</div>
		<div class="articlefoot">
			Author: $rs[log_Author] | Posted @ $time | Comment($rs[log_CommNums])
		</div>
		<script language="javascript" type="text/javascript">
			document.title = "$rs[log_Title]";
		</script>
	</div>\n
HTML;
	$sqlComm = "SELECT * FROM blog_comment where comm_LogID = '".$_GET['log_ID']."' order by comm_PostTime";
	$rss = $mysql->select($sqlComm);
	foreach( $rss as $rs )
	{
	   $time = strftime("%B %d,%Y,%H:%M %p",$rs->comm_PostTime);
print <<<HTML
    <div id="$rs[comm_ID]" class="comment">
        <div class="commenttitle"><a name="$rs[comm_ID]" >$rs[comm_Author] Posted @ $time </a></div>
        <div class="commentcontent">$rs[comm_Content]</div>
    </div>\n
HTML;
	}
	
	if($commentable)
	{
	print <<<HTML
	<div id="PostContent">
	<div id="Head" class="articletitle" style="text-align:center;"><a name="PostComment">发表评论</a></div>
	<div id="Body" class="articlecontent">     
	<form name="comment" action="javascript:void 0;" method="post" onsubmit="PostComment(this);void 0;" style="margin:0px;">	  
	<table width="100%" cellpadding="0" cellspacing="0">	  
	<tr>
    <td align="right" width="70">帐 户:</td>
	<td align="left" style="padding:3px;">
    <input name="username" type="text" size="18" class="userpass" maxlength="24" 
HTML;
	print "value='".$_SESSION['username']."' /></td></tr>";
    if(empty($_SESSION['username']))
    {
    print <<<HTML
    <tr>
	<td align="right" width="70">密 码:</td>
	<td align="left" style="padding:3px;">
	<input name="password" type="password" size="18" class="userpass" maxlength="24"/>&nbsp;&nbsp;*Guest not need password.
	</td>
	</tr>
HTML;
	}else{
	print <<<HTML
	<input name="password" type="hidden" size="18" class="userpass" maxlength="24"/>
HTML;
	}
	print <<<HTML
	<tr><td align="right" width="70">验 证:</td>
    <td align="left" style="padding:3px;">
    <input name="code" type="text" size="4" maxlength="4" style="width:40px;"/>
    <img height="18" src="./include/code.php" width="40"  />	
    </td>
	</tr>
	<tr>
	<td align="right" width="70" valign="top">评 论:<br/></td>
	<td>
    <div>
    <textarea name="commcontent" rows=15 cols=50 style=""></textarea>
    </div>
	</td>
    </tr>
    <tr>
    <td colspan="2" align="center" style="padding:3px;">
        <input name="logID" type="hidden" value="$log_ID" />
        <input name="action" type="hidden" value="SaveComment" />
        <input name="submit2" type="submit" value="提交"/>
        <input name="button" type="reset" value="清除"/>
    </td>
    </tr>	  
    </table>
    </form>
    </div>
    </div>		
HTML;
	}
    else
    {
        print <<<HTML
        <div align="center" style="clear:both; padding=20px;">本文已经禁止评论 </div>
HTML;
    }
	break;	
	default : break;
}
$mysql->close();

echo "\n  </div>";
ShowFooter();
echo "\n</div>\n<p>&nbsp;</p><br />\n";
    
?>
</body>
</html>
